package mxmf.repository;

import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import mxmf.entity.content.BaseContent;

public interface BaseContentRepository extends JpaRepository<BaseContent, Long> {

    List<List<String>> categoryByContentCode(List<String> codes);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update BaseContentQuery set folderCode=?2,updateTime=now() where id in ?1")
    void updateFolderCode(Long[] ids, String folderCode);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update BaseContentQuery set cdnStatus=?1,updateTime=now() where id = ?2")
    void updateCdnStatus(Integer cdnStatus, Long id);


    @Transactional
    void updateContent(BaseContent content, Map<String, Object> paramMap);

    BaseContent findByProgramId(Long programId);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update BaseContentQuery set charge = ?1 where id = ?2")
    void updateCharge(Integer charge, Long id);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query("update BaseContentQuery set ver =?2 where id = ?1")
    void updateVer(Long id, Integer ver);



    @Modifying
    @Transactional
    @Query("delete from BaseContentQuery b where b.id in (?1)")
    void deleteBatch(Long[] ids);

    void detach(BaseContent content);
}
